package com.example.administrator.recyclertext_312_ywl;

/**
 * Created by Administrator on 2017/5/15 0015.
 */

import android.support.v7.app.AppCompatActivity;
        import android.os.Bundle;
        import android.support.v7.widget.LinearLayoutManager;
        import android.support.v7.widget.RecyclerView;

        import java.util.ArrayList;
        import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
    }
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter mAdapter;
    List<ArticleBean> list;
    private void initRecyclerView() {
        recyclerView = (RecyclerView) findViewById(R.id.recylerview);    //创建默认的线性LayoutManager
        layoutManager = new LinearLayoutManager(this);    //设置布局管理器
        recyclerView.setLayoutManager(layoutManager);   //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        recyclerView.setHasFixedSize(true);   //创建并设置Adapter
        list = getData();
        mAdapter = new MyAdapter(this);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);}

    private List<ArticleBean> getData() {
        List<ArticleBean> list = new ArrayList<ArticleBean>();
        ArticleBean art;

        for(int i=1;i<7;i++) {
            art = new ArticleBean();
            art.setArticleId(1);
            art.setTitle("标题"+i);
            if(i==1)art.setImgid(R.drawable.f1);
            else if(i==2) art.setImgid(R.drawable.f2);
            else if(i==3) art.setImgid(R.drawable.f3);
            else if(i==4) art.setImgid(R.drawable.f4);
            else if(i==5) art.setImgid(R.drawable.f5);
            else if(i==6) art.setImgid(R.drawable.f6);
            art.setTime("2017-4-1 15:16");
            art.setDescription("描述"+i);
            list.add(art);
        }


        return list;

    }

}